package com.wuqi.dev.retrofitdemo.retrofit;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Risky57 on 2017/4/24.
 */

public class HttpManger {

    private static class SingletonHolder{
        private static final HttpManger INSTANCE = new HttpManger();
    }

    public static HttpManger getInstance(){
        return SingletonHolder.INSTANCE;
    }

    private Retrofit mRetrofit;
    // 普通的Retrofit
    private BearService mService;
    // 支持RxJava的Retrofit
    // 两种保留一个就可以
    private BearApi mApi;

    private HttpManger(){
        mRetrofit = new Retrofit.Builder()
                .baseUrl(BearService.BEAR_URL)
                // 加入Rxjava支持
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                // 添加解析框架
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        mService = mRetrofit.create(BearService.class);
        mApi = mRetrofit.create(BearApi.class);
    }

    public BearService getService () {
        return mService;
    }

    public BearApi getApi () {
        return mApi;
    }
}
